;#NoTrayIcon
timer1 = 0
timer2 = 0
timer3 = 0
timer4 = 0
timer01 = 0
mbtimer1 = 0
mbtimer2 = 0
mbtimer3 = 0
mbtimer4 = 0
mbtimer01 = 0
mbtimercount = 0
signalstrength = 0
kbsec = 0
gui, show, W440 H400 X800 Y100, Hughes Modem Status
Gui, Add, Progress, w60 h360 Vertical Range0-250 c006000 vMyProgress
Gui, Add, Progress, w50 h360 Vertical Range0-180 c00CCFF vSignalBar
Gui, Add, Progress, w20 h360 Vertical Range0-70 cAAAAAA vPowerWord
Gui, Add, Edit, R20 ReadOnly W200 vMyEdit
Gui, Add, Edit, R1 ReadOnly W112 -Multi vSignalTitle
Gui, Add, Edit, R1 ReadOnly W86 -Multi vPowerTitle
Gui, Add, Edit, R1 ReadOnly W140 -Multi vDLTitle
Gui, Add, Checkbox, vSignalBeepCheckbox , Play Audio when below 100 signal

GuiControl, MoveDraw, MyProgress, x10 y25
GuiControl, MoveDraw, SignalTitle, x228 y2
GuiControl, MoveDraw, SignalBar, x290 y25
GuiControl, MoveDraw, PowerTitle, x350 y2
GuiControl, MoveDraw, PowerWord, x390 y25
GuiControl, MoveDraw, MyEdit, x80 y50
GuiControl,, SignalTitle, Signal Strength
GuiControl, MoveDraw, DLTitle, x2 y2
GuiControl,, DLTitle, MB Remain
GuiControl,MoveDraw, SignalBeepCheckbox, x90 y330
settimer, start, 15000
settimer, signal, 1000
SetTitleMatchMode, 2
Process, Close, gavonlinechecker.exe
Run, gavonlinechecker.exe



start:
FileRead, currentping, ping.txt




FileGetTime, FileTime, DownloadStatus.txt, M ;read file date
FileAge = %A_Now% ;set a date

EnvSub, FileAge, %FileTime%, Seconds ;figure how old the file is

if (FileAge > 13 or FileTime < 1) {
UrlDownloadToFile, http://192.168.0.1/stlui/user/allowance_request.html, DownloadStatus.txt
}
FileGetTime, FileTime, DownloadStatus.txt, M ;read file date
FileRead, PageVar, DownloadStatus.txt


if(InStr(PageVar, "Allowance Remaining (MB)")){
}else{
return
}
Between(start, end, data){
strpos1 := InStr(data, start, true)
strlen1 += StrLen(start)
strpos1 += StrLen(start)
strpos2 := InStr(data, end, true,strpos1)
Length := (strpos2 - strpos1)
StringMid, output, data, strpos1, Length
stringreplace output, output, %A_Space%,,All
return output

}
MB1 := Between("Plan Allowance (MB)</td><td style=""border-width:0px;"">","</td></tr>", PageVar)
MB2 := Between("Remaining (MB)</td><td style=""border-width:0px;"">", "</td></tr><tr", PageVar)
percentremain := Between("Allowance Remaining (%)</td><td style=""border-width:0px;"">", "</td></tr><", PageVar)
timeremain := Between("Time Until Allowance Refill</td><td style=""border-width:0px;"">", "</td>", PageVar)
GuiControlGet, BarValue, ,MyProgress
GuiControlGet, SignalCheckbox, ,SignalBeepCheckbox

if(mbtimer1 = 0){
mbtimer1 = %MB2%
timer1 = %A_Now%
}

if(MB2 < BarValue){
timer4 := timer3
timer3 := timer2
timer2 := timer1
timer1 := A_Now

mbtimer4 := mbtimer3
mbtimer3 := mbtimer2
mbtimer2 := mbtimer1
mbtimer1 := MB2
}

if(mbtimer4 > 0 and MB2 < BarValue){
timer01 := A_Now
mbtimercount = 3
EnvSub, timer01, timer4, seconds
kbsec := ((mbtimer4 - mbtimer1) * 1024) / timer01
}
else if(mbtimer3 > 0 and MB2 < BarValue){
timer01 := A_Now
mbtimercount = 2
EnvSub, timer01, timer3, seconds
kbsec := ((mbtimer3 - mbtimer1) * 1024) / timer01
}
else if(mbtimer2 > 0 and MB2 < BarValue){
timer01 := A_Now
mbtimercount = 1
EnvSub, timer01, timer2, seconds
kbsec := ((mbtimer2 - mbtimer1) * 1024) / timer01
}

mbtimer1024 := ((MB2 * 1024) / kbsec)
mbexpireraw := %A_Now%
EnvAdd, mbexpireraw, %mbtimer1024%, seconds
FormatTime, mbexpire, %mbexpireraw%, MM-dd h:mm:ss tt
if(mbtimercount = 0){
mbexpire = N/A
}

timeoffset := InStr(timeremain, "`:")
StringMid, time1, timeremain, 1, timeoffset-1
StringMid, time2, timeremain, timeoffset+1, 2
StringMid, time3, timeremain, timeoffset+4, 2

secondsremain := ((time1 * 3600) + (time2 * 60)) + time3

;-----check if its freezone------
FormatTime, fz,,H

freezone := ""
if(fz > 0 and fz < 6){
freezone := "yes"
}
;--------end freezone check-----


;------allowed speed calculations--------
datenow = %A_Now%
FormatTime, datevar1, %A_Now%, yyyyMMdd01
datevar2 := datevar1
EnvAdd, datevar2, 1, Day

dv1 = %datevar1%

EnvSub, dv1, %datenow%, Seconds
EnvSub, dv2, %datenow%, Seconds
resettime = %A_Now%
resettime += %secondsremain%, Seconds

if (dv1 > 0){
 resettime -= %datevar1%, S

if(resettime > 18000){
secondsremain -= 18000
}else if (resettime > 0){
secondsremain -= %resettime%, Seconds
}

}else{
 resettime -= %datevar2%, S

if(resettime > 18000){
secondsremain -= 18000
}else if (resettime > 0){
secondsremain -= %resettime%, Seconds
}

}


kbsecallowed := (((MB2 - 5) * 1024) / secondsremain)
;------------Background Colors-------------------------
if(kbsecallowed > 120 or MB2 > 249 or freezone = "yes"){
Gui, Color, 50FF98
}else{
Gui, Color, ECE9D8
}

if (OnlineStatus == "off") {
Gui, Color, 333333
}
;----------------end Background Colors------------------

gavnumber := floor((MB2 * kbsecallowed) / 100)



;------end allowed speed calculations---------

;------audio playback------
if (MB2 < 26 and MB2 < BarValue){
SoundPlay, Speech\%MB2%.wav
}
;------end audio playback-------

EnvAdd, FileTime, %time3%, Seconds
EnvAdd, FileTime, %time2%, Minutes
EnvAdd, FileTime, %time1%, Hours
FormatTime, resettime, %FileTime%, hh:mm:ss tt
GuiControl,, MyEdit, %MB2% mb of %MB1% mb remains`nreset at %resettime%`n`n`nExtra Calculations:`n`nused %mbtimercount%mb`nover %timer01% seconds`nat %kbsec% KB/s`nEst mb Expire: %mbexpire%`n`nAllowed Speed: %kbsecallowed% kb/s`nfor: %secondsremain% seconds`n`nGav Number: %gavnumber%`n`nPing: %currentping%
GuiControl,,MyProgress, %MB2%
GuiControl,, DLTitle, MB Remain: %MB2% of %MB1%

if (MB2 < 50 and MB2 < BarValue) {
sleep 1000
WinRestore, Hughes Download Status
WinSet, AlwaysOnTop,, Hughes Download Status
WinSet, AlwaysOnTop,, Hughes Download Status
Loop 6{
Gui Flash
Sleep 500
}
}



;----------audio----------------
if(signalstrength < 10 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal10.mp3
}else if(signalstrength < 20 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal9.mp3
}else if(signalstrength < 30 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal8.mp3
}else if(signalstrength < 40 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal7.mp3
}else if(signalstrength < 50 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal6.mp3
}else if(signalstrength < 60 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal5.mp3
}else if(signalstrength < 70 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal4.mp3
}else if(signalstrength < 80 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal3.mp3
}else if(signalstrength < 90 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal2.mp3
}else if(signalstrength < 100 and SignalCheckbox){
SoundPlay, %A_WorkingDir%\Audio\Signal1.mp3
}
;---------------------end audio-------------------------



return

signal:

UrlDownloadToFile, http://192.168.0.1/stlui/user/system_status.html, SystemStatus.txt
FileRead, SysVar, SystemStatus.txt


signalstrength := Between("Receive Signal Strength</a></td>`n<td width=230>","`n</td></tr>", SysVar)
powerword := Between("Normalized Power Word</a></td>`n<td width=230>","`n</td></tr>", SysVar)

GuiControl,,SignalBar, %signalstrength%
GuiControl,,SignalTitle, Signal Strength: %signalstrength%
GuiControl,,PowerWord, %powerword%
GuiControl,,PowerTitle, Power Word: %powerword%

signaltime := (signalstrength / 5) + 0.5
signaltime := signaltime * 500
settimer, signal, %signaltime%
WinSetTitle,Hughes Modem Status,, %MB2%m %signalstrength%s Hughes Modem Status

return


guiclose:
Process, Close, gavonlinechecker.exe

exitapp
